﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 仿贴标机程序
{
    public partial class Form1 : Form
    {
        SQLServerDataBase sql = new SQLServerDataBase();
        public static string value;
        public Form1()
        {
            InitializeComponent();
           

        }
        public string form1name
        {
            get
            {
                return customer;
            }
            set
            {
                customer = value;
            }
        }
        private void up_Label_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
       
           

        }

        private void he_Label_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
         
        }

        private void boxBtw_label_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
           

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //加载界面，先查询有没有连接上打印机
        }

        private void button1_Click(object sender, EventArgs e)
        {//printClick
          int count =  sql.ExecuteSelect_jiuwei("SELECT COUNT(*)FROM[dbo].[View_SALES_DELIVERY_JW] WHERE ITEM_CODE = 'RC0805F N 0R P' AND[销货通知单号] = '2420-202503040010'");

            if (count>1)
            {
                if (MessageBox.Show("检测到有多个相同品号。请确认是否打印下标签?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)

                {

                    MessageBox.Show("打印下标签");

                }
                else
                {
                    MessageBox.Show("不打印下标签");

                }
               
            }



        }
       


        string customer = "";
        private void button2_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            DataSet ds1 = new DataSet();
           string sqlStr = "SELECT [序号], [销货通知单号],[客户名称],[客户编号],[收货地址],[品名],[订单单号],[ITEM_CODE],[单位],[数量], '0' as 已扫数量,[库位],[上标贴],[下标贴],[围套标],[外箱标],[客户材料货号],[供应商],[客户单号],[备注],[批号],[品号],[规格],[单据日期],[客户材料规格],[客户材料品名],[图号] FROM[JW2021].[dbo].[View_SALES_DELIVERY_JW] WHERE [销货通知单号] = '" + textBox_doc.Text + "'";

            try
            {
                sql.jiuwei_ExecuteNonDataSet(sqlStr, out ds);
                dataGridView1.DataSource = ds.Tables[0];

                customer = ds.Tables[0].Rows[0][2].ToString();
                label_cusmter.Text = customer;
                value = customer;
                string select_jw_bartender = "SELECT * FROM [dbo].[jw_bartender] WHERE custom_name = '" + customer + "'";
                sql.ExecuteNonDataSet(select_jw_bartender, out ds1);
                up_Label.Text = ds1.Tables[0].Rows[0][1].ToString();
                he_Label.Text = ds1.Tables[0].Rows[0][2].ToString();
                boxBtw_label.Text = ds1.Tables[0].Rows[0][3].ToString();
            
            }
            catch (Exception)
            {
                up_Label.Text = "null";
                he_Label.Text = "null";
                boxBtw_label.Text = "null";
                MessageBox.Show("可能的原因：1、输入单号不正确2、客户模板不存在");
                return;
            }


        

        }

        private void button3_Click(object sender, EventArgs e)
        {
            new loginFrom().ShowDialog();
        }
    }
}
